package com.imy.common.util;

public class HexUtils {
  private static final char[] HEX_CHAR = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

  /**
   * 方法一：将byte类型数组转化成16进制字符串
   * @explain 字符串拼接
   * @param bytes
   * @return
   */
  public static String toHexString(byte[] bytes) {
    StringBuilder sb = new StringBuilder();
    int num;
    for (byte b : bytes) {
      num = b < 0 ? 256 + b : b;
      sb.append(HEX_CHAR[num / 16]).append(HEX_CHAR[num % 16]);
    }
    return sb.toString();
  }
}
